package com.gof.example.flyweight;

/**
 * Created with IntelliJ IDEA.
 * Created by zhiyuan on 2018/5/8 09:38.
 * haiming.fei@tongdun.cn
 */
public class App {

    public static void main(String[] args) {
        Area a = new Area();
        Position p = new Position();
        SimpleResourceFactory instance = SimpleResourceFactory.instance();

        a.setHeight(180);
        a.setWidth(120);
        p.setX(120);
        p.setY(100);
        AbstractResource resource = instance.getResource("image");
        resource.insert(a, p);
        a.setHeight(50);
        a.setWidth(60);
        p.setX(10);
        p.setY(20);
        AbstractResource resource1 = instance.getResource("image");
        resource1.insert(a, p);
        System.out.println(resource == resource1);

        a.setHeight(50);
        a.setWidth(60);
        p.setX(10);
        p.setY(20);
        resource = instance.getResource("flash");
        resource.insert(a, p);
        a.setHeight(800);
        a.setWidth(1000);
        p.setX(130);
        p.setY(140);
        resource1 = instance.getResource("flash");
        resource1.insert(a, p);
        System.out.println(resource == resource1);

        a.setHeight(200);
        a.setWidth(300);
        p.setX(110);
        p.setY(130);
        resource = instance.getResource("txt");
        resource.insert(a, p);
        a.setHeight(500);
        a.setWidth(600);
        p.setX(110);
        p.setY(190);
        resource1 = instance.getResource("txt");
        resource1.insert(a, p);
        System.out.println(resource == resource1);
    }
}
